package Gather.SetExercise;

import java.util.Iterator;
import java.util.TreeSet;

/**
 * ClassName:TreeSetText002
 * Package:Gather.SetExercise
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/9-16:39
 * @Version:v1.0
 */
public class TreeSetText002 {
    /*需求：存储整数并进行排序*/
    public static void main(String[] args) {

        //创建TreeSet集合对象
        TreeSet<Integer> ts = new TreeSet<>();
        //添加元素
        ts.add(1);
        ts.add(4);
        ts.add(2);
        ts.add(5);
        ts.add(3);

        //迭代器遍历
        Iterator<Integer> it = ts.iterator();
        while (it.hasNext()) {
            int i = it.next();
            System.out.print(i+" ");
        }
        System.out.println();
        System.out.println("----------------");
        //增强for遍历
        for (Integer t : ts) {
            System.out.print(t+" ");
        }
        System.out.println();
        System.out.println("-----------------");
        //Lambda遍历
        ts.forEach(integer-> System.out.print(integer+" "));
    }
}
